//
//  ByCellProductEvaluateCommon.m
//  oc_knowledge
//
//  Created by pro on 17/1/19.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellProductEvaluateCommon.h"

@implementation ByCellLayoutProductEvaluateCommon

- (void)setModel:(ByModelProductEvaluate *)model {
    
    _model = model;
    
    CGFloat x, y, width, height;
    
    // 用户头像
    x               = 10;
    y               = 10;
    width           = 20;
    height          = width;
    _userIconFrame  = CGRectMake(x, y, width, height);
    
    // 用户昵称
    x               = CGRectGetMaxX(_userIconFrame) + 10;
    y               = CGRectGetMinY(_userIconFrame);
    width           = SCREEN_WIDTH - 10 - x;
    height          = CGRectGetHeight(_userIconFrame);
    _userNameFrame  = CGRectMake(x, y, width, height);
    
    // 规格
    x               = 10;
    y               = CGRectGetMaxY(_userNameFrame) + 10;
    width           = SCREEN_WIDTH - x * 2;
    height          = 15;
    _skuFrame       = CGRectMake(x, y, width, height);
    
    // 评价内容
    x               = 10;
    y               = CGRectGetMaxY(_skuFrame) + 5;
    width           = SCREEN_WIDTH - x * 2;
    height          = [model.content getRectOfStringWithSize:CGSizeMake(width, 10000) font:12].size.height;
    _contentFrame   = CGRectMake(x, y, width, height);
    
    // cell
    x               = 0;
    y               = 0;
    width           = SCREEN_WIDTH;
    height          = CGRectGetMaxY(_contentFrame) + 10;
    _cellFrame      = CGRectMake(x, y, width, height);
}
@end

@implementation ByCellProductEvaluateCommon
{
    UIImageView *_iconImgView;              // 头像
    UILabel     *_usernameLabel;            // 用户名
    UILabel     *_skuLabel;                 // 规格
    UILabel     *_contentLabel;             // 内容
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    // 头像
    _iconImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_iconImgView];
    
    // 用户名
    _usernameLabel = [[UILabel alloc] init];
    _usernameLabel.adjustsFontSizeToFitWidth = YES;
    _usernameLabel.font = FONT(14);
    _usernameLabel.textColor = [UIColor blackColor];
    _usernameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_usernameLabel];
    
    // 规格
    _skuLabel = [[UILabel alloc] init];
    _skuLabel.adjustsFontSizeToFitWidth = YES;
    _skuLabel.font = FONT(12);
    _skuLabel.textColor = [UIColor lightGrayColor];
    _skuLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_skuLabel];
    
    // 评价内容
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.adjustsFontSizeToFitWidth = YES;
    _contentLabel.numberOfLines = 0;
    _contentLabel.font = FONT(12);
    _contentLabel.textColor = [UIColor blackColor];
    _contentLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_contentLabel];
    
}
- (void)setLayout:(ByCellLayoutProductEvaluateCommon *)layout {
    
    _layout = layout;
    
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    ByModelProductEvaluate *model   = _layout.model;
    
    // 设置布局
    _iconImgView.frame              = _layout.userIconFrame;
    _usernameLabel.frame            = _layout.userNameFrame;
    _skuLabel.frame                 = _layout.skuFrame;
    _contentLabel.frame             = _layout.contentFrame;
    
    // 设置属性
    [_iconImgView setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:DEFAULT_IMAGE_1_2];
    _usernameLabel.text             = model.nickname;
    _skuLabel.text                  = [NSString stringWithFormat:@"%@    %@", model.create_time, model.sku_desc];
    _contentLabel.text              = model.content;
    
}


@end
